package com.rxjava.simpleflatmap;

import com.rxjava.User;

/**
 * Created by iceGeneral on 2016/10/15.
 */
public class Test {
    public static void main(String[] args) {

        Observable
        .create(new OnSubscribe<Integer>() {
            @Override
            public void call(Subscriber<? super Integer> subscriber) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                subscriber.onNext(6);
            }
        })
        .flatMap(new Func1<Integer, Observable<String>>() {
            @Override
            public Observable<String> call(Integer integer) {
            	System.out.println("step6");
                return Observable.from(new String[]{"flatMap" + integer, "flatMap" + (integer + 1), "flatMap" + (integer + 2)});
            }
        })
        .map(new Func1<String, User>() {
            @Override
            public User call(String name) {
                return new User(name);
            }
        })
        .subscribe(new Subscriber<User>() {
            @Override
            public void onNext(User user) {
                System.out.println(user);
            }
        });

    }

}
